<?php
session_start();
$_SESSION['shops'] = isset($_SESSION['shops'])?$_SESSION['shops']:array();
include "../public/common/common.php";
include "../public/common/config.php";
//echo $root;
$sqlAdvert = "select * from advert";
$resAdvert = mysql_query($sqlAdvert);
while($rowAdvert = mysql_fetch_assoc($resAdvert)){
	$rowAds[$rowAdvert['pos']] = $rowAdvert;
}

$sqlClass = "select * from class";
$resClass = mysql_query($sqlClass);
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<?php
		include "header.php"	
		?>
		<div class="advert">
			<img src="<?php echo $imgPath.$rowAds[0]['img']?>"/>
		</div>
		
		<div class="content">
			<?php
			while($rowClass = mysql_fetch_assoc($resClass)){
			?>
			<div class="floor">
				<div class="floorHeader">
					<div class="left">
						<span id="">
							<?php echo $rowClass['name']?>
						</span>
					</div>
					<div class="right">
						<span id="">
							热销产品
						</span>
						<span id="">
							<a href="class.php?class_id=<?php echo $rowClass['id']?>">更多</a>
						</span>
					</div>
				</div>
				<div class="floorFooter">
					<?php
					$sqlShop = "select shop.* from shop left join brand on(shop.brand_id = brand.id) left join class on(brand.class_id = class.id) where brand.class_id = {$rowClass['id']} and shop.shelf = 1 order by rand() limit 4";
					$resShop = mysql_query($sqlShop);
					while($rowShop = mysql_fetch_assoc($resShop)){
					?>
					
					<a href="shop.php?shop_id=<?php echo $rowShop['id']?>">
						<div class="shop">
							<div class="shopImg">
								<img src="<?php echo $imgPath . '/thumb_' . $rowShop['img']?>"/>
							</div>
							<div class="shopInfo">
								<span class="shopName">
									<?php echo $rowShop['name']?>
								</span>
								<span class="shopPrice">
									<?php echo $rowShop['price']?>元
								</span>
							</div>
						</div>
					</a>
					
					<?php	
					}
					?>
				</div>
			</div>
			<?php	
			}
			?>
		</div>
		
		<div class="advert">
			<img src="<?php echo $imgPath.$rowAds[1]['img']?>"/>
		</div>
	</body>
	
</html>